/**
 * Copyright (c) 2019 xstgongyi.org
 * All rights reserved.
 */
package org.xstgongyi.eduaid.controller;

import org.xstgongyi.eduaid.dataobject.StudentDO;
import org.xstgongyi.eduaid.bo.Gender;

/**
 * @author oldcrane<br/>
 * @created 2019-04-16
 */
class StudentControllerHelper {

	/**
	 * 修改指定对象的某个属性值。如果参数非法，返回false
	 */
	static boolean setAttribute(StudentDO student, String name, String value) {
		if (null == name || null == value || null == student) {
			return false;
		}

		// 可以考虑用反射,减少代码量，性能略有降低。
		switch (name) {
		case "name":
			student.setName(value);
			return true;
		case "gender":
			student.setGender(Gender.valueOf(value));
			return true;
		case "idNumber":
			student.setIdNumber(value);
			return true;
		case "description":
			student.setDescription(value);
			return true;
		case "regSchool":
			student.setRegSchool(value);
			return true;
		case "regGradeId":
			student.setRegGradeId(Integer.parseInt(value));
			return true;
		case "contactPhone":
			student.setContactPhone(value);
			return true;
		case "contactWechat":
			student.setContactWechat(value);
			return true;
		case "contactEmail":
			student.setContactEmail(value);
			return true;
		case "contactOther":
			student.setContactOther(value);
			return true;
//		case "povertyLevel":
//			student.setPovertyLevel(value);
//			return true;
		case "suggestAmount":
			student.setSuggestAmount(Integer.parseInt(value));
			return true;
		default:
			return false;
		}
	}

}
